<div class="page-content">
    <!-- BEGIN PAGE HEADER-->
	<div class="row">
		<div class="col-md-12">
			<!-- BEGIN PAGE TITLE & BREADCRUMB-->
			<h3 class="page-title">
		          Edit Article
			</h3>
			<ul class="page-breadcrumb breadcrumb">
				<li>
					<i class="fa fa-home"></i>
					<a href="<?php echo $this->Admin->admin_url() ?>">
						Home
					</a>
					<i class="fa fa-angle-right"></i>
				</li>
				<li>
					<a href="<?php echo $this->Admin->admin_url() ?>article/index">
						Article list
					</a>
					<i class="fa fa-angle-right"></i>
				</li>
				<li>
					<a href="javascript:void(0)">
						Edit Article
					</a>
				</li>
			</ul>
			<!-- END PAGE TITLE & BREADCRUMB-->
		</div>
	</div>
	<!-- END PAGE HEADER-->
	<!-- BEGIN PAGE CONTENT-->
    <div class="row">
        <div class="col-md-12">
        	<!-- BEGIN VALIDATION STATES-->
        	<div class="portlet box blue">
        		<div class="portlet-title">
        			<div class="caption">
        				<i class="fa fa-reorder"></i>Managed_table
        			</div>
        		</div>
        		<div class="portlet-body form">
                <?php
                    if(!empty($article_info['article']))
                    {
                ?>
        			<!-- BEGIN FORM-->
        			<!--form action="" id="form_category" class="form-horizontal" method="post"-->
                    <?php
                        echo $this->Form->create('Article', array(
                                                            'url' => array('controller' => 'article', 'action' => 'edit', $article_id, $parent_id), 
                                                            'type' => 'post',
                                                            'id' => 'form_article',
                                                            'class' => 'form-horizontal'));
                    ?>
                        <input type="hidden" name="article_id" id="article_id" value="<?php echo $article_id ?>" />
        				<div class="form-body">
                            <div class="form-group">
        						<label class="control-label col-md-3">Category parent
        						<span class="required">
        							 *
        						</span>
        						</label>
        						<div class="col-md-4">
                                    
                                    <select id="" class="form-control select2me" name="category_id">
                                        <option value="">Choose one caregory</option>
                                        <?php
                                            foreach($list_category as $value)
                                            {
                                                $level = $value['level'];
                                                $span = "";
                                                for($j = 0; $j < $level; $j++)
                                                    $span .= '--&nbsp&nbsp';
                                                $selected = $value['category_id'] == $article_info['article']['category_id'] ? "selected='selected'" : "";
                                                                                                        
                                                echo '<option '.$selected.' value="'.$value['category_id'].'">'.$span.$value['title'].'</option>';
                                            }
                                        ?>
                                    </select>
        						</div>
        					</div>
                            <div class="form-group">
        						<label class="control-label col-md-3">Status
                                    <span class="required">*</span>
        						</label>
        						<div class="col-md-4">
                                    <div class="radio-list" data-error-container="#form_2_membership_error">
										<?php
                                            $checkEnable = "";
                                            $checkDisable = "";
                                            if($article_info['article']['status'] == 1)
                                                $checkEnable = 'checked="checked"';
                                            else
                                                $checkDisable = 'checked="checked"';
                                        ?>
                                        <label>
										<input <?php echo $checkEnable ?> type="radio" name="status" value="1"/>
										Enable </label>
										<label>
										<input <?php echo $checkDisable ?> type="radio" name="status" value="0"/>
										Disable </label>
									</div>
        						</div>
        					</div>
                            
                            <div class="form-group">
        						<label class="control-label col-md-3">Sort order
                                 </label>
        						<div class="col-md-4">
                                    <?php
                                        echo $this->Form->text('sort_order',
                                                        array(
                                                            'label' => false,
                                                            'div' => false,
                                                            'class' => 'form-control',
                                                            'value' => $article_info['article']['sort_order']
                                                        )
                                        );
                                    ?>
        						</div>
        					</div>
                            
                            <?php
                                $main_image = 'images/no-image.jpg';
                                if(!empty($list_image))
                                {
                                    $main_image = isset($list_image['main_image']['name']) ? $list_image['main_image']['name'] : $main_image;
                                }
                            ?>
                            <div class="form-group">
        						<label class="control-label col-md-3">Image&nbsp;&nbsp;</label>
        						<div class="col-md-4">
                                    <div class="btn-group btn-group-xs btn-group-solid">
                                        <img id="main_image" class="show_image_browse" src="<?php echo $this->webroot ?><?php echo $main_image ?>" />
                                        <input class="main_image" type="hidden" name="main_image" value="<?php echo $this->webroot ?><?php echo $main_image ?>" />
                                        <div class="clear"></div>
                                        <button class="btn blue fileBrowse" data-target="main_image" type="button">Browse File</button>
										<button class="btn red fileDelete" data-target="main_image" type="button">Delete File</button>
								    </div>
                                </div>
        					</div>
                            <div class="form-group">
        						<label class="control-label col-md-3">Image other&nbsp;&nbsp;</label>
        						<div class="col-md-8 other_image">
                                    <?php
                                        if(!empty($list_image))
                                        {
                                            $other_image = isset($list_image['other_image']) ? $list_image['other_image'] : array();
                                            $i = 1;
                                            foreach($other_image as $image)
                                            {
                                    ?> 
                                            <div class="btn-group btn-group-xs btn-group-solid">
                                                <img src="<?php echo $this->webroot . $image['name'] ?>" class="show_image_browse" id="other_image_<?php echo $i ?>"/>
                                                <input type="text" title="Sort order" name="order_image[]" value="<?php echo $image['sort_order'] ?>" class="order_other_image"/>
                                                <input type="hidden" value="<?php echo $this->webroot . $image['name'] ?>" name="other_image[]" class="other_image_<?php echo $i ?>"/>
                                                <div class="clear"></div>
                                                <button type="button" data-target="other_image_<?php echo $i ?>" class="btn blue fileBrowse">Browse File</button>
                                                <button type="button" data-target="other_image_<?php echo $i ?>" class="btn red fileDelete">Delete File</button>
                                            </div>
                                    <?php
                                            $i++;
                                            }
                                        }
                                    ?>
                                    <div class="btn_add_image">
                                        <img src="<?php echo $this->webroot ?>img/add-image.png" alt="add_image" />
                                    </div>
                                    
                                </div>
        					</div>
                            
                            <div class="form-group">
        						<label class="control-label col-md-3">Other</label>
        						<div class="col-md-9">
                                   <?php
                                   /*
                                        echo $this->Form->input('other',
                                                                        array(
                                                                            'label' => false,
                                                                            'div' => false,
                                                                            'class' => 'form-control',
                                                                            'id' => 'other'
                                                                        )
                                                        );
                                   */
                                   ?>
                                   <input type="text" value="<?php echo $article_info['article']['other'] ?>"  id="other" class="form-control" name="data[Article][other]"/>
                                </div>
        					</div>
                            
                            <div class="">
        						<label class="control-label col-md-3"></label>
        						<div class="col-md-9">
                        			<div class="tabbable tabbable-custom">
                        				<ul class="nav nav-tabs">
                                            <?php
                                                $i=0;
                                                foreach($list_language as $language)
                                                {
                                                    $language = $language['language'];
                                                    $lang_code = $language['lang_code'];
                                            ?>
                        					<li class='<?php echo $i++==0 ? "active" : "" ?>'>
                        						<a data-toggle="tab" href="#tab_<?php echo $lang_code ?>">
                        							 <img src="<?php echo $this->webroot; ?>admin/img/flags/<?php echo $lang_code ?>.png" />
                                                     <?php echo $language['title'] ?>
                        						</a>
                        					</li>
                                            <?php
                                                }
                                            ?>
                        				</ul>
                        				<div class="tab-content">
                                            <?php
                                                $i = 0;
                                                foreach($list_language as $language)
                                                {
                                                    $language = $language['language'];
                                                    $lang_code = $language['lang_code'];
                                            ?>
                                            <div id="tab_<?php echo $lang_code ?>" class="tab-pane <?php echo $i++==0 ? "active" : "" ?>">
                                                <div class="form-group">
                            						<label class="control-label mgl15">Title
                                                        <span class="required">*</span>
                            						</label>
                            						<div class="col-md-12">
                            							<input type="text" id="title_<?php echo $lang_code ?>" name="title_<?php echo $lang_code ?>" lang_code="<?php echo $lang_code ?>" class="form-control" value="<?php echo $article_info['article_desc'][$lang_code]['title'] ?>"/>
                            						</div>
                            					</div>
                                                <div class="form-group">
                            						<label class="control-label mgl15">Link
                                                        <span class="required">*</span>
                            						</label>
                            						<div class="col-md-12">
                            							<input type="text" lang_code="<?php echo $lang_code ?>" id="link_<?php echo $lang_code ?>" name="link_<?php echo $lang_code ?>" class="form-control" value="<?php echo @$article_info['link'][$lang_code]['link'] ?>"/>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                            						<label class="control-label mgl15">
                                                        Short description
                            						</label>
                            						<div class="col-md-12">
                            							<textarea id="description_<?php echo $lang_code ?>" class="form-control" name="description_<?php echo $lang_code ?>" rows="6"><?php echo $article_info['article_desc'][$lang_code]['description'] ?></textarea>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                            						<label class="control-label mgl15">
                                                        Long description
                            						</label>
                            						<div class="col-md-12">
                            							<textarea class="ckeditor form-control" name="long_description_<?php echo $lang_code ?>" rows="6"><?php echo $article_info['article_desc'][$lang_code]['long_description'] ?></textarea>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                            						<label class="control-label mgl15">
                                                        Meta title
                                                    </label>
                            						<div class="col-md-12">
                            							<input type="text" name="meta_title_<?php echo $lang_code ?>" class="form-control" value="<?php echo $article_info['article_desc'][$lang_code]['meta_title'] ?>"/>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                                                    <label class="control-label mgl15">
                                                        Meta description
                            						</label>
                            						<div class="col-md-12">
                            							<textarea name="meta_description_<?php echo $lang_code ?>" class="form-control"><?php echo $article_info['article_desc'][$lang_code]['meta_description'] ?></textarea>
                            						</div>
                                                </div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                                                    <label class="control-label mgl15">
                                                        Meta_keywords
                            						</label>
                            						<div class="col-md-12">
                            							<textarea name="meta_keywords_<?php echo $lang_code ?>" class="form-control"><?php echo $article_info['article_desc'][$lang_code]['meta_keywords'] ?></textarea>
                            						</div>
                                                </div>
                                                <!--END_INPUT_FORM-->
                                                <div class="clearfix"></div>
                        					</div>
                        					<!--end tab-pane-->
                                            <?php
                                                }
                                            ?>
                        					<!--end tab-pane-->
                                            <div class="clearfix"></div>
                        				</div>
                                        
                        			</div>
                        		</div>
        					</div>
                            <div class="clearfix"></div>
        				</div>
        				<div class="form-actions fluid">
        					<div class="col-md-offset-3 col-md-9">
                                <button type="submit" class="btn blue" name="btn_submit" value="ok">Submit</button>
        						<button type="button" class="btn default" onclick="window.location.href='<?php echo $this->Admin->admin_url() ?>article/index/<?php echo $parent_id ?>'">Cancel</button>
        					</div>
        				</div>
                        
        			<?php echo $this->Form->end(); ?>
        			<!-- END FORM-->
        		</div>
                <?php
                    }
                    else
                    {
                        echo "Article not found";
                    }
                ?>
        		<!-- END VALIDATION STATES-->
        	</div>
        </div>
    </div>
</div>
<!-- END CONTENT -->
<script type="text/javascript" src="<?php echo $this->webroot; ?>ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>ckfinder/ckfinder.js"></script>
<script>
    <?php
        foreach($list_language as $language)
        {
            $language = $language['language'];
            $lang_code = $language['lang_code'];
    ?>
    var description_<?php echo $lang_code ?> = CKEDITOR.replace('description_<?php echo $lang_code ?>');
    CKFinder.setupCKEditor( description_<?php echo $lang_code ?>, '<?php echo $this->webroot ?>ckfinder/' );
    var long_description_<?php echo $lang_code ?> = CKEDITOR.replace('long_description_<?php echo $lang_code ?>');
    CKFinder.setupCKEditor( long_description_<?php echo $lang_code ?>, '<?php echo $this->webroot ?>ckfinder/' );
    <?php
        }
    ?>

</script>
